package zcj.stu.dao;

import com.mongodb.client.result.DeleteResult;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import zcj.stu.Entity.Category;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class CategoryDao {
    @Resource
    private MongoTemplate mongoTemplate;

    public Category add(Category category) {
        return mongoTemplate.insert(category);
    }
    public com.mongodb.client.result.UpdateResult edit(Query query, Update update) {
        return mongoTemplate.updateFirst(query,update,Category.class);
    }

    public DeleteResult del(Query query) {
        return mongoTemplate.remove(query,Category.class);
    }

    public List<Category> all() {
        return mongoTemplate.findAll(Category.class);
    }
}
